package dao.oracle;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import bean.KoordinatBean;
import bean.loader.KoordinatLoader;
import dao.DAOFactory;
import dao.ResourceManager;

public class KoordinatDao {
	private DAOFactory factory;
	
	public KoordinatDao(DAOFactory factory) {
		super();
		this.factory = factory;
	}

	public KoordinatBean getKoordinatWhereId(int id) throws SQLException{
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		try {
			conn = factory.getConnection();
			ps = conn.prepareStatement("SELECT * FROM KOORDINAT WHERE ID_KOORD = ?");
			ps.setInt(1, id);
			rs = ps.executeQuery();
			if(rs.next())
				return new KoordinatLoader().loadSingle(rs);
			return null;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new SQLException(e);
		} finally{
			ResourceManager.close(rs);
			ResourceManager.close(ps);
		}
	}
}
